package com.ticket.sass.admin.manager

/**
 * 用于维护是否开启租户隔离
 */
object MybatisTenantIgnoreManager {
    data class IgnoreField(
        val tenantId: Boolean = false,
        val cinemaId: Boolean = false,
    )

    private val valueHolder = ThreadLocal<IgnoreField>()

    fun setValue(value: IgnoreField) {
        valueHolder.set(value)
    }

    fun getValue(): IgnoreField? {
        return valueHolder.get()
    }

    fun <T>autoInjectDestroy(ignoreField: IgnoreField, callback: () -> T): T {
        try {
            setValue(ignoreField)

            return callback()
        } finally {
            valueHolder.remove()
        }
    }
}